home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Simple i/o for my class
- Date: 30 Jan 1996 08:05 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <30JAN199608051674@erich.triumf.ca>
- References: <4ekjql$5jl@nnrp1.news.primenet.com>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4ekjql$5jl@nnrp1.news.primenet.com>, mcoplea@primenet.com (Marty R. Coplea) writes...
- >I am having a little trouble with a batting average program.
- >It seems to take the input OK, but always returns a '0' for the Batting
- >Average. Please look at the following code and make any suggestions. Thank
- >you in advance for any assistance you can offer. (email perfered)
-
- .. snip...
- > /* Prompt the user to input the data */
- > printf("Enter the number of at-bats followed by hits: ");
- > scanf("%f %f", &avar, &hvar);
-
- It is often better to get user input with fgets(), then use sscanf() - it
- gives you a better chance to recover from entry errors.
- >
- > /* Convert to integers */
- > Atbatsint = avar;
- > Hitsint = hvar;
-
- Why??
- >
- > /* Calculate the Batting Average */
- > Avg = Hitsint/Atbatsint;
-
- The division will be done with integer arithmetic, where
- (small number)/(big number) is always zero.
-
- Since Avg is a float, why not leave the Atbats and Hits as floats? Then you
- should get the expected results.
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-